package byx.container.annotation.extension.impl;

import byx.container.annotation.annotation.Order;
import byx.container.annotation.extension.core.ClassPostProcessorContext;
import byx.container.annotation.extension.core.ClassProcessorContext;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 处理条件注入的类
 */
@Order(Integer.MAX_VALUE - 1)
public class ConditionalClassProcessor extends ConditionalRegisterProcessor {
    public ConditionalClassProcessor(ClassScanner classScanner, List<ConditionalAnnotationHandler<?>> handlers) {
        super(classScanner, handlers);
    }

    @Override
    public List<ClassPostProcessorContext> process(ClassProcessorContext ctx) {
        Class<?> type = ctx.getType();
        ConditionalAnnotationHandler<?> handler = findConditionalAnnotationHandler(type);
        if (handler != null && needToRegister(type, handler, ctx)) {
            return new ArrayList<>(getTypeAndMethodContexts(type));
        }
        return Collections.emptyList();
    }
}
